Learning Objectives

After completing this lesson, you’ll be able to:

Transformer-Based Attribute Mapping

After filtering your data with a transformer like the Tester or the TestFilter, you can create attributes or set their values based on these divisions. Here, an author divides data into neighborhoods using a postcode attribute and the TestFilter:

Example using data mapping and filtering transformers

However, many AttributeManager transformers like this are not a good idea. They bloat the workspace, making it hard to navigate and edit. They don't scale well, either. Since each value needs a separate TestFilter port and AttributeManager combination, it's easy to imagine the difficulties involved with more than 50 values!

One solution is to use a simple AttributeValueMapper transformer. However, that transformer only permits a single simple condition, such as X=Y. If a more advanced set of conditions is required, the preferred solution is conditional attribute values.

What are Conditional Attribute Values?

You can use conditional attribute values instead of many transformers of the same type. Instead of creating a set of conditions and values as separate objects in a workspace, you set both conditions and values inside a single transformer.

The option for conditional attribute values is in the drop-down dialog wherever you can provide an attribute value. For example, in the AttributeManager:

Conditional Value.. option in the Attribute Manager

In the above screenshot, a workspace author creates a new attribute called NEIGHBORHOOD. The values for NEIGHBORHOOD are conditional upon other attribute values and, in this example, are set up like this:

Defining Condition Statements

Note

Copy and paste conditions using the Copy Row and Paste Row buttons to save time and prevent data entry errors. You can copy and paste between transformers of a similar style, e.g., the Tester and TestFilter.

Like the AttributeValueMapper, a series of conditions (left) map to different values (right). However, unlike the AttributeValueMapper, this dialog allows much more complex conditions than a simple 1:1 mapping. That’s because full test capabilities are built into this dialog.

The conditions are defined by double-clicking in the Test Condition field to open up a Tester-style dialog. Both the condition and the output value can be set within this dialog:

Setting the Attribute Value result of a test

Many options beyond simple text or numbers are available for setting the Attribute Value in the Parameter Conditional Definition dialog:

Options for Attribute Value result from a test

Once the conditions are set, the original dialog – in this case, an AttributeManager – looks like this, with the number of conditions defining the number of possible values:

AttributeManager showing multiple possible values

Note

Like attribute construction, conditional values apply to attributes and most FME parameters. For example, you can create labels conditional upon specific tests using the Labeller transformer itself:

Using conditional values for an FME parameter

This way, you don't have to create the labels in an AttributeManager and then apply them in the Labeller as a separate task.

Note

You can use cached values in some transformers when providing an attribute value. This feature makes it faster and easier to build tests. For example, you could use this feature to filter out a specific value from NEIGHBORHOOD, searching the list of neighborhood names to find the correct one.

In a transformer with a cache and an attribute value parameter, click the drop-down arrow and choose Cached Values (if available). A list of values is displayed to choose from, including a search filter.

When to Use Conditional Attribute Values?

Conditional attribute values are great for mapping (or setting) an attribute in relation to the value of an existing attribute, and when the conditions are more complex than can be handled in a simple AttributeValueMapper (or AttributeRangeMapper) transformer.

In essence, conditional values are like a combination of TestFilter and AttributeCreators.

As with most tasks in FME, conditional values are just one of multiple ways to carry out a task. The other primary technique is conditional filtering followed by data mapping.

Conditional filtering means separating the data according to attribute values. Data mapping means we set an attribute value according to the value of other attributes.

Here is an example of how we might mix filtering data (by coastal zone, in this example) with mapping data (by elevation).

We can combine these steps using conditional values. The filter conditions and value mapping are incorporated as the conditions for our conditional values. 

Using conditional values usually means fewer transformers on the canvas, but does this improve the workspace? Is it a more aesthetic (good-looking) workspace? The decision on which method to use may depend on who will maintain the workspace. In most cases, conditional filters or data mapping are both valid options. If you "hide" a lot of logic in a Conditional Value calculation, call it out by attaching an annotation. Summary annotation is particularly useful, since it will automatically update if you change the logic.

Leave Us Feedback on This Lesson